package controllers;

import java.io.InputStream;
import java.util.List;

import models.City;
import models.FeedBack;
import models.Message;
import models.TakeMeTour;
import models.ToursicItem;
import models.Type;
import play.db.jpa.GenericModel;
import play.mvc.Controller;

public class Application extends Controller {

	public static void getAllTypes() {
		List<Type> allTypes = Type.findAll();
		renderXml(allTypes);
	}

	public static void getImageByType(int typeId) {
		Type type = Type.findById((long) typeId);
		if (type.image.get() != null) {
			renderBinary(type.image.get());
		} else {
			renderHtml("pas de figure");
		}
	}

	public static void getAllCities() {
		List<City> allCities = City.findAll();
		renderXml(allCities);
	}

	public static void addFeedBack(String message) {
		FeedBack fb = new FeedBack(message);
		fb.save();
	}
	
	public static void getAllTmt() {
		List<TakeMeTour> takeMeTour = TakeMeTour.findAll();
		renderXml(takeMeTour);
	}

	public static void getAllTourItemsByType(int typeId) {
		Type type = Type.findById((long) typeId);
		List<ToursicItem> allTourItems = ToursicItem.find("byType", type)
				.fetch();
		renderXml(allTourItems);
	}

	public static void getAllTourItems() {
		List<ToursicItem> allTourItems = ToursicItem.findAll();
		renderXml(allTourItems);
	}

	public static void getAllMessages() {
		List<Message> listMessages = Message.findAll();
		renderXml(listMessages);
	}
	
	public static void getTypeByItemId(int idItem) {
		ToursicItem toursicItem = ToursicItem.findById((long) idItem);
		Type type = toursicItem.type;
		renderXml(type);
	}
}